package com.yilin.tms.message.common.configurer;

import com.yilin.tms.message.common.interceptor.ChatHandshakeInterceptor;
import com.yilin.tms.message.service.impl.SocketService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;


@Configuration
@EnableWebSocket
@EnableWebMvc
public class WebSocketServerConfig implements WebSocketConfigurer {
    public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
        webSocketHandlerRegistry.addHandler(myHandler(),"/message/socket/data").addInterceptors(new ChatHandshakeInterceptor());
        webSocketHandlerRegistry.addHandler(myHandler(),"/message/sockJs/socket/data").addInterceptors(new ChatHandshakeInterceptor()).withSockJS();
    }
    @Bean
    public WebSocketHandler myHandler(){
        return new SocketService();
    }
}

